import { defineStore } from 'pinia'
export const pkStore = defineStore(
    'pk',
    {
    state: () => ({
        status: "matching",  // matching表示匹配界面，playing表示对战界面
        socket: null,
        opponent_username: "",
        opponent_photo: "",
        gamemap: null,
        a_id: 0,
        a_sx: 0,
        a_sy: 0,
        b_id: 0,
        b_sx: 0,
        b_sy: 0,
        // 为了访问gamemap里面的store
        gameObject: null,

        loser: "none", //all,A,B
    }),
    getters: {
    },
    // mutations: {
    //     updateSocket(state, socket) {
    //         state.socket = socket;
    //     },
    //     updateOpponent(state, opponent) {
    //         state.opponent_username = opponent.username;
    //         state.opponent_photo = opponent.photo;
    //     },
    //     updateStatus(state, status) {
    //         state.status = status;
    //     },
    //     updateGame(state,game) {
    //         state.gamemap = game.gamemap;
    //         state.a_id = game.a_id;
    //         state.a_sx = game.a_sx;
    //         state.a_sy = game.a_sy;
    //         state.b_id = game.b_id;
    //         state.b_sx = game.b_sx;
    //         state.b_sy = game.b_sy;
    //     },
    //     updateGameObject(state,gameObject){
    //         state.gameObject = gameObject;
    //     },
    //     updateLoser(state,loser){
    //         state.loser = loser;
    //     }
    // },
    actions: {
        updateSocket(socket) {
            this.socket = socket;
        },
        updateOpponent(opponent) {
            this.opponent_username = opponent.username;
            this.opponent_photo = opponent.photo;
        },
        updateStatus(status) {
            this.status = status;
        },
        updateGame(game) {
            this.gamemap = game.gamemap;
            this.a_id = game.a_id;
            this.a_sx = game.a_sx;
            this.a_sy = game.a_sy;
            this.b_id = game.b_id;
            this.b_sx = game.b_sx;
            this.b_sy = game.b_sy;
        },
        updateGameObject(gameObject){
            this.gameObject = gameObject;
        },
        updateLoser(loser){
            this.loser = loser;
        }
    },

    }
)
